#!/bin/bash

Current_TIME=`date "+%Y-%m-%d %H:"`
File_TIME=`date "+%Y%m%d"`

#经信委
j1=`zabbix_get -s 10.64.2.1 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/10.65.0.253/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`
j2=`zabbix_get -s 10.64.2.2 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/10.65.0.253/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`


#判断两个场点是否正常,1为正常,0未不正常
if (( ${j1}==1 || ${j2}==1 )); then
	jingxinwei=1
else
	jingxinwei=0 
fi

if (( ${jingxinwei}==1 )) ; then
	echo "`date "+%Y-%m-%d %H:%M:%S"` 经信委没问题" >> /home/rduser/check_ac_available/ac.log
	exit
fi

#mail
send_mail(){
local -a Mail_error

if (( ${jingxinwei}==0 )); then
	jingxinwei_error="过去2小时,经信委场点认证有问题!"
	Mail_error+=(${jingxinwei_error})
fi

echo "`date "+%Y-%m-%d %H:%M:%S"`" ${Mail_error[*]} >> /home/rduser/ac.log
printf "%s" "${Mail_error[*]}" | mutt -s "i-Guangdong 场点认证监控" jc.wu@windfindtech.com chaoli.ye@windfindtech.com ronald.zhao@windfindtech.com
}

send_mail
